<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>人员新增</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}"/>
</head>
<body>
    <form class="layui-form" th:action="@{/user/add}" method="post" style="margin-top: 15px">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="userName" required="required"  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="passWord" required="required" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input"/>
            </div>
            <div class="layui-form-mid layui-word-aux">密码不要太简单,请牢记</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="1" title="男" checked="checked"/>
                <input type="radio" name="sex" value="0" title="女"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
                <input type="text" name="age" required="required" lay-verify="required|number" placeholder="请输入年龄" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Email</label>
            <div class="layui-input-inline">
                <input type="text" name="email" required="required"  lay-verify="required|email" placeholder="请输入email" autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" required="required"  lay-verify="required|phone" placeholder="请输入电话号码" autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">启用</label>
            <div class="layui-input-block">
                <input type="checkbox" name="enable" checked="checked" lay-skin="switch"/>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="lay-submit" lay-filter="formUser">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</body>
<script th:src="@{/static/layui/layui.all.js}"></script>
<script>
    var ctxPath = /*[[@{/}]]*/ '';
    layui.use('form', function(){
        var form = layui.form;
        var index = parent.layer.getFrameIndex(window.name);

        //监听提交
        form.on('submit(formUser)', function(data){
            layui.$.post({
                url:ctxPath + '/user/add',
                data:data.field,
                success:function (res) {
                    if(res.status){
                        layui.$.get({
                            url:ctxPath + '/user/toPageList',
                            success:function () {
                                parent.layer.close(index);
                            }
                        });
                    }else {
                        layer.msg(JSON.stringify(data.message));
                    }
                }
            });
            return false;
        });

    });
</script>
</html>